(function () {

	'use strict';

	angular
		.module('app')
		.controller('MyCardController', MyCardController);

    MyCardController.$inject = ['$scope', '$http', '$window', '$timeout', '$location', '$state', '$stateParams', 'API', 'ENUM', 'PaymentModel', 'MyCardModel', 'OrderExpressModel'];

    function MyCardController($scope, $http, $window, $timeout, $location, $state, $stateParams, API, ENUM, PaymentModel, MyCardModel, OrderExpressModel) {
        $scope.TAB_ALL = 0;
		$scope.TAB_CREATED = 1;
		$scope.TAB_PAID = 2;

		$scope.currentTab = $scope.TAB_ALL;

		$scope.cancellingOrder = null;
		$scope.showDialog = false;

		$scope.MyCardModel = MyCardModel;
		$scope.paymentModel = PaymentModel;
		$scope.orderExpressModel = OrderExpressModel;

		if ($stateParams.tab == 'all') {
			$scope.currentTab = $scope.TAB_ALL;
			$scope.MyCardModel.status = null;
		} else if ($stateParams.tab == 'created') {
			$scope.currentTab = $scope.TAB_CREATED;
			$scope.MyCardModel.status = ENUM.ORDER_STATUS.CREATED;
		} else if ($stateParams.tab == 'paid') {
			$scope.currentTab = $scope.TAB_PAID;
			$scope.MyCardModel.status = ENUM.ORDER_STATUS.PAID;
		}

		$scope.touchTabAll = function () {
            if ($scope.currentTab != $scope.TAB_ALL) {
                $scope.currentTab = $scope.TAB_ALL;
                $scope.MyCardModel.status = null;
                $scope.MyCardModel.reload();
            }
        };
		$scope.touchTabCreated = function () {
            if ($scope.currentTab != $scope.TAB_CREATED) {
                $scope.currentTab = $scope.TAB_CREATED;
                $scope.MyCardModel.status = 1;
                $scope.MyCardModel.reload();
            }
        };
		$scope.touchTabPaid = function () {
            if ($scope.currentTab != $scope.TAB_PAID) {
                $scope.currentTab = $scope.TAB_PAID;
                $scope.MyCardModel.status = 2;
                $scope.MyCardModel.reload();
            }
        };
		$scope.touchCard = function(card_id) {
			if (card_id) {
				$state.go('confirm-card', {
                    card_id: card_id
				});
			}
		}


		$scope.MyCardModel.reload();
	}

})();